function navigationNew() { 
    workspace.clear();
}
function navigationOpen() { }
function navigationSave() {  
    d_save();
}
function navigationExport() { }
function navigationSettings() { }
function getCssVariables(e, o = "") {
    let t = {};
    for (var r in e) "object" == typeof e[r] ? t = Object.assign(t, getCssVariables(e[r], o + "-" + r)) : t[o + "-" + r] = e[r]; return t
} function setCssVariables(e) {
    var o, t = getCssVariables(e);
    for (o in t) document.documentElement.style.setProperty("-" + o, t[o])
}
function getCookie(o) {
    var t = document.cookie.split("; ");
    for (let e = 0; e < t.length; e++) {
        var r = t[e].split("=");
        if (r[0] === o) return r[1]
    }
    return ""
}
$(document).ready(function () { $("#navigation").click(function (e) { e.stopPropagation(), $(".boxyMenu").toggle(100), $(".boxyMenu").is(":visible") && $(document).one("click", function () { $(".boxyMenu").hide(100) }) }), $(".boxyMenu").on("click", function (e) { e.stopPropagation() }) }), $(".boxyMenu").hide(), setCssVariables((boxyTheme = { light: { toolbox: { bar: { color: "#525252", background: "#ffffff" }, flyout: { background: "#ffffff" }, label: { selected: { color: "#000000", background: "#ffffff" }, unselected: { color: "#000000", background: "transparent" } } }, workspace: { background: "#ffffff" } }, dark: { toolbox: { bar: { color: "#ffffff", background: "#373737" }, flyout: { background: "#202020" } }, workspace: { background: "#2e2e2e" } } })[getCookie("themeMode") || "light"]);
class CustomCategory extends Blockly.ToolboxCategory {
    constructor(e, o, t) {
        super(e, o, t)
    } addColourBorder_(e) {
        this.rowDiv_.style.backgroundColor = e
    }
    setSelected(e) {
        var o = this.rowDiv_.getElementsByClassName("blocklyTreeLabel")[0];
        e ? (this.rowDiv_.style.backgroundColor = "var(--toolbox-label-selected-background)", o.style.color = "") : (this.rowDiv_.style.backgroundColor = "", o.style.color = "var(--toolbox-label-unselected-color)"), Blockly.utils.aria.setState(this.htmlDiv_, Blockly.utils.aria.State.SELECTED, e)
    }
    createIconDom_() {
        var e = document.createElement("img");
        return e.src = this.cssConfig_.path,
            e.color = "white",
            e.style = `height:20px;width:20px;`,
            e
    }
}
console.log(window.innerHeight);
Blockly.registry.register(Blockly.registry.Type.TOOLBOX_ITEM, Blockly.ToolboxCategory.registrationName, CustomCategory, !0);
var workspace, trashcanSwitch = function (e) {
    var o = document.getElementById("trashcan-lid").style,
        t = document.getElementById("trashcan-body").style,
        r = document.getElementById("trashcan").style;
    if (e) {
        o.zIndex = 7,
            t.zIndex = 7,
            r.zIndex = 6,
            o.opacity = 1,
            t.opacity = 1,
            r.opacity = 1;
        var n = function () {
            var e = 0,
                o = window.event;
            if (o) return o.pageX ?
                e = o.pageX : o.clientX && (e = o.clientX + document.documentElement.scrollLeft + document.body.scrollLeft), e
        }() || n;
        trashCover(n < 60)
    } else {
        o.opacity = 0,
            t.opacity = 0,
            r.opacity = 0;
        try {
            o.zIndex = 0,
                t.zIndex = 0,
                r.zIndex = 0
        } catch (e) { }
    }
},
    trashCover = function (e) {
        var o = document.getElementById("trashcan-lid").style;
        o.transform = e ? "translate(-4px,-4px) rotate(-20deg)" : "translate(0px) rotate(0deg)"
    };
function loadWorkspace() {
    var n = document.getElementById("blocklyArea"),
        a = document.getElementById("blocklyDiv");
    workspace = Blockly.inject("blocklyDiv", {
        toolbox: document.getElementById("toolbox"),
        plugins: {
            blockDragger: ScrollBlockDragger,
            metricsManager: ScrollMetricsManager
        },
        trashcan: !1,
        zoom: {
            controls: !0,
            wheel: !0,
            startScale: .8,
            maxScale: 1.6,
            minScale: .4,
            scaleSpeed: 1.5
        },
        move: {
            scrollbars: !0,
            drag: !0,
            wheel: !0
        },
        theme: "zelos",
        renderer: "zelos"
    }),
        new WorkspaceSearch(workspace).init();
    function e(e) {
        let o = n,
            t = 0,
            r = 0;
        for (;
            t += o.offsetLeft,
            r += o.offsetTop,
            o = o.offsetParent;
        );
        a.style.left = t + "px",
            a.style.top = r + "px",
            Blockly.svgResize(workspace)
    }
    new ScrollOptions(workspace).init();
    window.addEventListener("resize", e, !1),
        e(), Blockly.svgResize(workspace)
}
$.ajax({
    url: "./static/boxy/toolbox/toolbox.xml",
    type: "get",
    async: !0,
    dataType: "xml",
    success: function (e) {
        e = $(e).find("toolbox").html();
        $("#toolbox").html(e),
            localStorage.setItem("toolbox", e),
            loadWorkspace()
    },
    error: function (e, o, t) {
        $("#toolbox").html(localStorage.getItem("toolbox") || ""),
            console.error("Boxy Error: An unknown error occurred in toolbox."),
            console.error("Boxy is loading the data from the storage instead."),
            console.error("Please check your settings and try again."),
            console.error(e),
            console.error("ErrorType:", o),
            console.error(t),
            loadWorkspace()
    }
}
);